package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import cn.itcast.crm.domain.Customer;

public interface CustomerDao extends JpaRepository<Customer, Integer> {
	
	 List<Customer> findByFixedAreaIdIsNull();
	 
	 @Modifying
	 @Query("update Customer c set c.fixedAreaId=null where c.fixedAreaId=:fid")
	 void unblindByFixedId(@Param("fid")String fid);
	 List<Customer> findByFixedAreaId(String fixedAreaId);
	 
	 @Query("update  Customer c set c.fixedAreaId=:fid where id in :cids")
	 @Modifying
	void associate(@Param("cids")List<Integer> cids, @Param("fid")String fid);

	 @Query("update Customer c set c.type=1 where c.telephone=:telephone")
	 @Modifying
	void updateCustomer(@Param("telephone")String telephone);
	 
	 @Query("from Customer c where c.telephone=:telephone")
	Customer getByTelephone(@Param("telephone")String telephone);

	Customer findByTelephoneAndPassword(String telephone, String password);
}
